<%@ page import="Entity.Merchant" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="Entity.Merchandise" %>
<%@ page import="Dao.McdDao" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.util.Collections" %>
<%@ page import="java.util.Comparator" %>
<%@ page import="Dao.MctDao" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>

<style>
    .button {
        padding: 2px 8px;
        margin: -2px;
        text-align: center;
        text-decoration: none;
        color: #2194E0;
        border: 2px solid #2194E0;
        font-size: 16px;
        display: inline-block;
        border-radius: 0.3em;
        transition: all 0.2s ease-in-out;
        position: relative;
        overflow: hidden;
        cursor: pointer;
    }

    .button:before {
        content: "";
        background-color: rgba(255,255,255,0.5);
        height: 100%;
        width: 3em;
        display: block;
        position: absolute;
        top: 0;
        left: -4.5em;
        transform: skewX(-45deg) translateX(0);
        transition: none;

    }
    .button:hover {
        background-color: #2194E0;
        color: #fff;
    }

    .button:hover {
        border-bottom: 4px solid darken(#2194E0, 10%);
    }

    .button:hover:before {
        transform: skewX(-45deg) translateX(13.5em);
        transition: all 0.5s ease-in-out;
    }
    .changepage{
        background-color: #4CAF50;
        border: none;
        color: white;
        padding: 5px 10px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
        border-radius: 5%;
        margin: 4px 2px;
        cursor: pointer;

        webkit-transition-duration: 0.4s;
        /* Safari */ transition-duration:0.4s;
    }

    .changepage:hover{
        box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
    }
    .logo h4{
        color:#fff;
        text-transform:uppercase;
        font-size:6em;
        font-family: 'bebas_neueregular';
    }
    .changepage{
        background-color: #4CAF50;
        border: none;
        color: white;
        padding: 5px 10px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
        border-radius: 5%;
        margin: 4px 2px;
        cursor: pointer;
        webkit-transition-duration: 0.4s;
        /* Safari */ transition-duration:0.4s;
    }
    .changepage:hover{
        box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
    }
    .turnpage{
        background-color: white;
        border: none;
        color: #4CAF50;
        padding: 5px 10px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
        border-radius: 5%;
        margin: 4px 2px;
        cursor: pointer;
        webkit-transition-duration: 0.4s;
        /* Safari */ transition-duration:0.4s;
    }
    .turnpage:hover{
        box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
    }
    .nowpage{
        background-color: white;
        border: none;
        color: #4CAF50;
        padding: 5px 10px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
        border-radius: 5%;
        margin: 4px 2px;
        webkit-transition-duration: 0.4s;
        box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
    }

</style>

<head>
    <title>虎蜂电子商务管理平台</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
    <link href="css/table.css" rel="stylesheet" type="text/css" media="all" />
    <script language="JavaScript" type="application/javascript">
        function confirm_del(id, loc, username, pagenum){
            if(confirm("确定要注销这家商铺吗？")){
                console.log(id, username, pagenum);
                location.href = "mctdel?id="+ id +"&loc="+ loc +"&pagenum=" + pagenum+"&username=" + username;
            }
        }
    </script>
</head>
<body>
<div class="wrap-box"> </div>
<div class="header">
    <div class="wrap">
        <div class="header-top">
            <div class="cssmenu">
                <ul>
                    <li><a href="home?username=${username}"><span>Home</span></a></li>
                    <li class="active"><a href="merchant?username=${username}&pagenum=1"><span>Merchant</span></a></li>
                    <li class="has-sub"><a href="merchandise?username=${username}&pagenum=1"><span>Merchandise</span></a></li>
                    <a href="index.jsp"><img : style="position: absolute;right: 200px; top: 20px" src ="image/goback.png" /></a>
                </ul>
            </div>
            <div class="logo">
                <h4><img style="width: 138.6px;height: 106px" src ="image/logo.png" />虎蜂</h4>
            </div>
        </div>
    </div>
</div>
<div class="main">
    <div class="wrap">
        <div class="about">
            <div class="about-top">
                <div class="col span_1_of_about">
                    <form action="mctsearch" method="get"><div>
                        <h3>商铺列表 &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                            &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                            <button style="border: 0px;height: 16px;width: 16px;
                            background-image:url(image/search.png);background-size:contain;
                            position: relative;left: 100px"
                                    type="submit" value="search"></button>
                            <input type="hidden" name="username" value="${username}"/>
                            <input type="hidden" name="pagenum" value="1"/>
                            <input class="searchbox" type="text" name="key"/>
                        </h3>
                    </div></form>
                    <div>
                    <table class="altrowstable">
                        <tr>
                            <th></th><th>商号</th><th>商铺名称</th><th>店主姓名</th><th>操作</th>
                        </tr>
                        <c:forEach items="${list}" begin="${page.num*10-10}" end="${page.num<page.maxnum?page.num*10-1:page.total-1}" var="merchant" varStatus="status">
                            <tr>
                                <td>${status.index + 1}</td>
                                <td>${merchant.id}</td>
                                <td>${merchant.name}</td>
                                <td>${merchant.belongto}</td>
                                <td>
                                    <script> const LOC = "del";</script>
                                    <button class="button"
                                            onclick="confirm_del(${merchant.id},'del','${merchant.username}',${page.num})">注销</button>
                                    &nbsp;&nbsp;
                                    <button class="button"
                                            onclick="location.href='mctupdate?id=${merchant.id}&username=${username}&pagenum=${page.num}'">修改</button>
                                </td>
                            </tr>

                        </c:forEach>
                    </table>
                        <c:if test="${page.num>1}">
                            <button class="changepage"
                                    onclick="location.href='merchant?username=${username}&pagenum=${page.num-1}'">上一页</button>
                        </c:if>
                        <button class="turnpage"
                                onclick="location.href='merchant?username=${username}&pagenum=1'"><<</button>
                        <c:if test="${page.num>2}">
                            <c:if test="${page.num>3}">......</c:if>
                            <button class="turnpage"
                                    onclick="location.href='merchant?username=${username}&pagenum=${page.num-2}'">${page.num-2}</button>
                        </c:if>
                        <c:if test="${page.num>1}">
                            <button class="turnpage"
                                    onclick="location.href='merchant?username=${username}&pagenum=${page.num-1}'">${page.num-1}</button>
                        </c:if>
                        <button class="nowpage">${page.num}</button>
                        <c:if test="${page.num<page.maxnum}">

                            <button class="turnpage"
                                    onclick="location.href='merchant?username=${username}&pagenum=${page.num+1}'">${page.num+1}</button>

                        </c:if>
                        <c:if test="${page.num<page.maxnum-1}">
                            <button class="turnpage"
                                    onclick="location.href='merchant?username=${username}&pagenum=${page.num+2}'">${page.num+2}</button>
                            <c:if test="${page.num<page.maxnum-2}">......</c:if>
                        </c:if>
                        <button class="turnpage"
                                onclick="location.href='merchant?username=${username}&pagenum=${page.maxnum}'">>></button>
                        <c:if test="${page.num<page.maxnum}">
                            <button class="changepage"
                                    onclick="location.href='merchant?username=${username}&pagenum=${page.num+1}'">下一页</button>
                        </c:if>
                    </div>
                </div>
                <div class="col span_1_of_about1">
                    <div class="contact-form">
                        <h3>新增商铺</h3>
                        <div class="sidebar-nav">
                            <form action="mctadd" method="post">
                                <input type="hidden" name="username" value="${username}"/>
                                <input type="hidden" name="pagenum" value="${page.num}"/>
                                <div>
                                    <span><label>商铺名称</label></span>
                                    <span><input class="textbox" type="text" name="name"/></span>
                                </div>
                                <div>
                                    <span><label>店主</label></span>
                                    <span><input class="textbox" type="text" name="belongto"/></span>
                                </div>
                                <div>
                                    <input type="hidden" name="username" value="${username}"/>
                                    <input class="btn" type="submit" value="Submit"/>
                                </div>
                            </form>
                        </div>
                    </div>
                    <%
//                        //获取资产配比
//                        Double sum = 0.0;
//                        List<Merchant> Mctlist = MctDao.queryByKey("",request.getParameter("username"));
////                        ArrayList<Merchant> Mctlist = new ArrayList<>(list);
//                        for(Merchant merchant:Mctlist){
//                            ArrayList<Merchandise> ownlist = null;
//                            try {
//                                ownlist = McdDao.queryBymctid(merchant.getId());
//                            } catch (SQLException throwables) {
//                                throwables.printStackTrace();
//                            } catch (ClassNotFoundException e) {
//                                e.printStackTrace();
//                            }
//
//                            Double own = 0.0;
//                            for (Merchandise merchandise:ownlist){
//                                own+=merchandise.getPrice()*merchandise.getNum();
//                            }
//                            merchant.setW(own);
//                            sum += own;
//                        }
//                        Collections.sort(Mctlist, new Comparator<Merchant>() {
//                            @Override
//                            public int compare(Merchant o1, Merchant o2) {
//                                if (o2.getW()>o1.getW()) return 1;
//                                else if(o2.getW()==o1.getW()) return 0;
//                                else return -1;
//                            }
//                        });
//                        if(Mctlist.size()>5) request.setAttribute("Mctlist",Mctlist.subList(0,5));
//                        else request.setAttribute("Mctlist",Mctlist);
//                        request.setAttribute("sum",sum);
                    %>
                    <h3>资产配比</h3>
                    <div class="poling">
                        <c:forEach items="${Mctlist}" var="it">
                            <div class="poll">
                                <div class="text2">商号： &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                                    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                                    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                                        ${it.id}</div></br>
                                <div class="text2">${it.name}</div>
                                <div class="percent" ><fmt:formatNumber value="${it.w/sum*100}" maxFractionDigits="2" />%</div>
                                <div class="clear"></div>
                                <div class="skills">
                                    <div style="width: ${Math.round(it.w/sum*100)}%"> </div>
                                </div>
                            </div>
                        </c:forEach>
                    </div>
                </div>
                <div class="clear"></div>
            </div>
        </div>
    </div>
</div>
<div class="footer">
    <div class="copy">
        <p>Copyright© 2022 虎蜂电子商务管理平台 20206769 陆天佑</p>
    </div>
</div>

</body>
</html>